package com.zjsx.lib.utils;


import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class PrefUtil {
    public static SharedPreferences settings;

    public static void init(Context context) {
	settings = PreferenceManager.getDefaultSharedPreferences(context);
    }

    public static String getString(String key, final String defaultValue) {
	return settings.getString(key, defaultValue);
    }

    public static void setString(final String key, final String value) {
	settings.edit().putString(key, value).commit();
    }

    public static boolean getBoolean(final String key, final boolean defaultValue) {
	return settings.getBoolean(key, defaultValue);
    }

    public static boolean hasKey(final String key) {
	return settings.contains(key);
    }

    public static void setBoolean(final String key, final boolean value) {
	settings.edit().putBoolean(key, value).commit();
    }

    public static void setInt(final String key, final int value) {
	settings.edit().putInt(key, value).commit();
    }

    public static int getInt(final String key, final int defaultValue) {
	return settings.getInt(key, defaultValue);
    }

    public static void setFloat(final String key, final float value) {
	settings.edit().putFloat(key, value).commit();
    }

    public static float getFloat(final String key, final float defaultValue) {
	return settings.getFloat(key, defaultValue);
    }

    public static void setLong(final String key, final long value) {
	settings.edit().putLong(key, value).commit();
    }

    public static long getLong(final String key, final long defaultValue) {
	return settings.getLong(key, defaultValue);
    }

    public static void clear(Context context, final SharedPreferences p) {
	final Editor editor = p.edit();
	editor.clear();
	editor.commit();
    }
}
